package GUI;
import processing.core.PImage;

public class Button extends Component
{
	public boolean state;
	public boolean pressed;
	public String label;
	////////////////////////////////////////////////////////////////////////////////////////////////////
	public Button()
	{
		state = false;
	}
	public void setLabel1(String name)
	{
		label1 = name;
		width = (int)(Utils.globalProcessing.textWidth(name)) + 10;
		if(icon != null) width += 15;
		height = 30;
	}
	public void setLabel2(String name)
	{
		label2 = name;
		width = (int)(Utils.globalProcessing.textWidth(name)) + 10;
		if(icon != null) width += 15;
		height = 30;
	}
	public void draw()
	{
		Utils.globalProcessing.textFont(Utils.plotFont, 14);
		width = (int)(Utils.globalProcessing.textWidth(label)) + 10;

		int cx = x;
		int cy = y;
		if(icon != null)
		{
			Utils.globalProcessing.image(icon, cx - 8, y);
		}
		if(label != null)
		{
			Utils.globalProcessing.textAlign(Utils.globalProcessing.LEFT);

			if(mouseOver()) 
			{
				super.draw();
				if(Utils.globalProcessing.mousePressed)
				{
					Utils.gu.drawBox(x, y, width, height, 0, Utils.globalProcessing.color(150, 150, 200), 255);
					Utils.gu.drawBox(x, y, width, height, 1, Utils.globalProcessing.color(150, 150, 200), 150);
					cx += 2;
					cy += 2;
					pressed = true;

				}
				else if(pressed)
				{
					Utils.graphArea.horizontalScrollBar.val=0;
					pressed = false;
					if(label!="Dialog" && label !="CatchPhrases"){
					if(state){
					state = false;
					label = label2;
					}
					else {
						state = true;
						label = label1;
					}
					}
					else{
						if(!state){
							state = true;
							label=label2;
						}
						else if(Utils.characterSelected.size()>0 &&Utils.catchPhrasesSelected.size()>0){	
							 state = false;
							 label = label1;
						}
							
					}
					Utils.graphArea.createLineGraphPoints();
				}
			}
			else
			{
				pressed = false;
			}

			Utils.globalProcessing.strokeWeight(1);
			Utils.globalProcessing.fill(Utils.textColor);
			Utils.globalProcessing.text(label, cx + 5, cy + 20);
		}
	}

	////////////////////////////////////////////////////////////////////////////////////////////////////
	PImage icon;
	String label1;
	String label2;
}